package com.flyqiu.form.api.rule;

import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.flyqiu.form.common.enums.FlyQiuFormDataAction;
import com.flyqiu.form.model.entity.FlyQiuTableConfig;

public interface FlyQiuDataRuleManage {
    /**
     * 注册数据验证规则
     *
     * @param rule 数据规则
     */
    void registerDataRule(FlyQiuFormDataRule rule);

    /**
     * 取消注册数据验证规则
     *
     * @param rule 数据规则
     */
    default FlyQiuFormDataRule unregisterDataRule(FlyQiuFormDataRule rule) {
        return unregisterDataRule(rule.getValue());
    }

    /**
     * 取消注册数据验证规则
     *
     * @param ruleValueKey 规则key
     * @return {@link FlyQiuFormDataRule}
     */
    FlyQiuFormDataRule unregisterDataRule(String ruleValueKey);

    /**
     * 验证单表单数据
     *
     * @param config     表单配置
     * @param formData   待验证的数据
     * @param dataAction 数据操作类型{@link FlyQiuFormDataAction}
     */
      void validateForm(FlyQiuTableConfig config, JSONObject formData, FlyQiuFormDataAction dataAction);




    /**
     * 验证列表数据
     *
     * @param config     表单配置
     * @param dataSource       待验证的数据
     * @param dataAction 数据操作类型{@link FlyQiuFormDataAction}
     */
    void validateListData(FlyQiuTableConfig config, JSONArray dataSource, FlyQiuFormDataAction dataAction);



}
